//
//  CMDBHomeBaseViewController.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/7.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let kTitleViewH : CGFloat = 44

class CMDBHomeBaseViewController: ShowLogoViewController {
    
    // MARK:- 懒加载属性
    lazy var pageTitleView : CMDBPageTitleView = {[weak self] in
        
        let titleFrame = CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: kTitleViewH)
        
        let titles = ["动态", "公告", "相关影人"]
        
        let titleView = CMDBPageTitleView(frame: titleFrame, titles: titles)
        
        titleView.backgroundColor = UIColor.Hex(0xfdfdfd)
        
        titleView.delegate = self
        
        return titleView
        }()
    
    
    lazy var pageContentView : CMDBPageContentView = {[weak self] in
        
        // 1.确定内容的frame
        let contentH = CMDB_Screen_Height - KStatusBarHeight - KNavBarHeight - kTitleViewH - KTabBarHeight
        let contentFrame = CGRect(x: 0, y: kTitleViewH, width: CMDB_Screen_Width, height: contentH)
        
        // 2.确定所有的子控制器
        var childVcs = [UIViewController]()
        let topicVc  = CMDBHomeTopicViewContorller()
//        topicVc.superNav = self!.superNav
        topicVc.superNav = self!.navigationController as? CustomNavigationControllerViewController
        
        childVcs.append(topicVc)
        childVcs.append(CMDBHomeNoticeViewController())
        childVcs.append(CMDBHomeRelatedPeopleViewController())

        
        let contentView = CMDBPageContentView(frame: contentFrame, childVcs: childVcs, parentController: self)
        contentView.delegate = self
        return contentView
        }()

    
    override func setup() {
        super.setup()
        
        
    }
    
    override func buildTitleView() {
        super.buildTitleView()
        
    }
    
    override func buildContentView() {
        
        super.buildContentView()
        
        contentView?.addSubview(pageTitleView)
   
        contentView?.addSubview(pageContentView)
    }

}

extension CMDBHomeBaseViewController {
    

}


// MARK:- PageTitleViewDelegate协议
extension CMDBHomeBaseViewController : CMDBPageTitleViewDelegate{
    
    func pageTitleView(titleView: CMDBPageTitleView, selectedIndex index: Int) {
     
        pageContentView.setCurrentIndex(index)
        
    }
}

// MARK:- PageContentViewDelegate协议
extension CMDBHomeBaseViewController : CMDBPageContentViewDelegate {
    
    func contentView(titleView: CMDBPageContentView, progress: CGFloat, sourceIndex: Int, targetIndex: Int) {
        
        pageTitleView.setTitleWithProgress(progress, sourceIndex: sourceIndex, targetIndex: targetIndex)
    }
}